package com.corpcredit.webapp.action;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.component.UISelectBoolean;

import com.corpcredit.model.Cpxs;
import com.corpcredit.model.Jbqk;
import com.corpcredit.service.GenericManager;
import com.corpcredit.service.LookupManager;

public class CpxsList extends BasePage implements Serializable {
	private LookupManager lookupManager;
	
	private GenericManager<Cpxs, Long> cpxsManager;

	private Jbqk jbqk;
	
	public void setJbqk(Jbqk jbqk) {
		this.jbqk = jbqk;
	}

	public void setLookupManager(LookupManager lookupManager) {
		this.lookupManager = lookupManager;
	}

	public CpxsList() {
		setSortColumn("id"); // sets the default sort column
	}

	public List getCpxss() {
		return sort(lookupManager.findAllByJbqkID(Cpxs.class, jbqk.getId()));
	}

	/**
	 * <p>
	 * The <code>checked</code> field for the current row.
	 * </p>
	 */
	private UISelectBoolean checked = null;

	public UISelectBoolean getChecked() {
		return checked;
	}

	public void setChecked(UISelectBoolean checked) {
		this.checked = checked;
	}

	@SuppressWarnings("unchecked")
	public String delete() {
		List removes = new ArrayList();
		UIData data = (UIData) checked.getParent().getParent();
		int n = data.getRowCount();
		for (int i = 0; i < n; i++) {
			data.setRowIndex(i);
			if (checked.isSelected()) {
				removes.add(data.getRowData());
			}
		}
		cpxsManager.removeAll(removes);
		return null;
	}
	
	public void setCpxsManager(GenericManager<Cpxs, Long> cpxsManager) {
		this.cpxsManager = cpxsManager;
	}
}
